package helperClassSearch;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class CreateHashMaps {
	public static void CreateHashMapsFile(int[] sheetNumbers, String fileName, String packageName, String className) {

		File replacedFile = new File(fileName);
		replacedFile.delete();

		try {
			Workbook workbook = Workbook.getWorkbook(new File("C:\\Documents and Settings\\Administrator\\My Documents\\Dropbox\\CTA\\XLS\\CTA.xls"));
			FileWriter fstream = new FileWriter(fileName);
			BufferedWriter textFile = new BufferedWriter(fstream);

			textFile.write("package com.cyclingthealps." + packageName + ";\n");
			textFile.write("\n");
			textFile.write("import java.util.HashMap;\n");
			textFile.write("import com.cyclingthealps.client.planned.MyMessagesPlanned;\n");
			textFile.write("import com.cyclingthealps.client.protour.MyMessagesProTour;\n");
			textFile.write("import com.cyclingthealps.client.climbs.MyMessagesClimbs;\n");
			textFile.write("import com.google.gwt.core.client.GWT;\n");
			textFile.write("import com.google.gwt.maps.client.geom.LatLng;\n");
			textFile.write("\n");
			textFile.write("			public class HashMaps {\n");
			textFile.write("public static MyMessages res = (MyMessages) GWT.create(MyMessages.class);\n");
			textFile.write("public static MyMessagesPlanned resPlanned = (MyMessagesPlanned) GWT.create(MyMessagesPlanned.class);\n");
			textFile.write("public static MyMessagesProTour resProTour = (MyMessagesProTour) GWT.create(MyMessagesProTour.class);\n");
			textFile.write("public static MyMessagesClimbs resClimbs = (MyMessagesClimbs) GWT.create(MyMessagesClimbs.class);\n");
			textFile.write("\n");

			textFile.write("public static java.util.Map<String, LatLng> locationsByLinks = new HashMap<String, LatLng>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				} else {
					if (sheetNumbers[d] == 11) {
						resources = "resProTour.";
					} else {
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						} else {
							resources = "resPlanned.";
						}
					}

				}
				textFile.write("\n");
				for (int i = 1; i < count.length; i++) {
					Cell latlngCellX = sheet.getCell(1, i);
					String latlngX = latlngCellX.getContents();
					Cell latlngCellY = sheet.getCell(2, i);
					String latlngY = latlngCellY.getContents();
					Cell passLinkCell = sheet.getCell(34, i);
					String passLink = passLinkCell.getContents();

					textFile.write("locationsByLinks.put(" + resources + passLink + "(), LatLng.newInstance(" + latlngX + "," + latlngY + "));\n");

				}

			}
			textFile.write("}\n");

			textFile.write("public static java.util.Map<String, String> siteNameByLinks = new HashMap<String, String>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				} else {
					if (sheetNumbers[d] == 11) {
						resources = "resProTour.";
					} else {
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						} else {
							resources = "resPlanned.";
						}
					}

				}
				textFile.write("\n");
				for (int j = 1; j < count.length; j++) {
					Cell passLinkCell = sheet.getCell(34, j);
					String passLink = passLinkCell.getContents();
					Cell siteNameCell = sheet.getCell(9, j);
					String siteName = siteNameCell.getContents();
					textFile.write("siteNameByLinks.put(" + resources + passLink + "(), \""+ siteName + "\");\n");

				}

			}
			textFile.write("}\n");
			textFile.write("\n");

			textFile.write("public static java.util.Map<String, String> passLinkByOracle = new HashMap<String, String>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				} else {
					if (sheetNumbers[d] == 11) {
						resources = "resProTour.";
					} else {
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						} else {
							resources = "resPlanned.";
						}
					}

				}
				textFile.write("\n");
				for (int j = 1; j < count.length; j++) {
					Cell passOracleCell = sheet.getCell(40, j);
					String passOracle = passOracleCell.getContents();
					Cell passLinkCell = sheet.getCell(35, j);
					String passLinkEN = passLinkCell.getContents();
					textFile.write("passLinkByOracle.put(" + resources + passOracle + "(), \""+ passLinkEN + "\");\n");

				}


			}
			
			textFile.write("}\n");
			
			textFile.write("public static java.util.Map<String, String> passLinkBySiteName = new HashMap<String, String>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);

				textFile.write("\n");
				for (int j = 1; j < count.length; j++) {
					Cell passSiteNameCell = sheet.getCell(9, j);
					String siteName = passSiteNameCell.getContents();
					Cell passLinkCell = sheet.getCell(35, j);
					String passLinkEN = passLinkCell.getContents();
					textFile.write("passLinkBySiteName.put(\""+ siteName + "\", \""+ passLinkEN + "\");\n");

				}


			}
			
			textFile.write("}\n");

			textFile.write("public static java.util.Map<String, String> threeSixtyString = new HashMap<String, String>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				} else {
					if (sheetNumbers[d] == 11) {
						resources = "resProTour.";
					} else {
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						} else {
							resources = "resPlanned.";
						}
					}

				}
				textFile.write("\n");
				for (int j = 1; j < count.length; j++) {
					Cell passLinkCell = sheet.getCell(34, j);
					String passLink = passLinkCell.getContents();
					Cell panoramaCell = sheet.getCell(51, j);
					String panorama = panoramaCell.getContents();
					textFile.write("threeSixtyString.put(" + resources + passLink + "(), \""+ panorama + "\");\n");

				}

			}
			
			textFile.write("}\n");

			textFile.write("public static java.util.Map<String, String> picturesString = new HashMap<String, String>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				} else {
					if (sheetNumbers[d] == 11) {
						resources = "resProTour.";
					} else {
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						} else {
							resources = "resPlanned.";
						}
					}

				}
				textFile.write("\n");
				for (int j = 1; j < count.length; j++) {
					Cell passLinkCell = sheet.getCell(34, j);
					String passLink = passLinkCell.getContents();
					Cell picturesCell = sheet.getCell(30, j);
					String pictures = picturesCell.getContents();
					textFile.write("picturesString.put(" + resources + passLink + "(), \""+ pictures + "\");\n");

				}

			}
			textFile.write("}\n");

			textFile.write("public static java.util.Map<String, String> videoString = new HashMap<String, String>();\n");
			textFile.write("static {\n");

			for (int d = 0; d < sheetNumbers.length; d++) {
				Sheet sheet = workbook.getSheet(sheetNumbers[d]);
				Cell[] count = sheet.getColumn(0);
				String resources;
				if (sheetNumbers[d] == 0 || sheetNumbers[d] == 1 || sheetNumbers[d] == 2 || sheetNumbers[d] == 3) {
					resources = "res.";
				} else {
					if (sheetNumbers[d] == 11) {
						resources = "resProTour.";
					} else {
						if (sheetNumbers[d] == 17) {
							resources = "resClimbs.";
						} else {
							resources = "resPlanned.";
						}
					}

				}
				textFile.write("\n");
				for (int j = 1; j < count.length; j++) {
					Cell passLinkCell = sheet.getCell(34, j);
					String passLink = passLinkCell.getContents();
					Cell videoCell = sheet.getCell(29, j);
					String video = videoCell.getContents();
					textFile.write("videoString.put(" + resources + passLink + "(), \""+ video + "\");\n");

				}

			}	
			
			
			textFile.write("}\n");
			textFile.write("}\n");
			textFile.write("\n");
			textFile.close();
			
		} catch (BiffException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
